﻿#region Copyrigth and License
/*==============================================================================
 *  Copyright (c) cndotnet.org Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.cndotnet.org/ezsocio
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DusonFramework.ContactService.Email {
    class MsResover {
        #region Fields

        #endregion

        #region Constructors

        #endregion

        #region Properties

        #endregion

        #region Events

        #endregion

        #region Methods
        public static MailContractCollection Resove(string html) {
            var mc = new MailContractCollection();
            var list = WebOpHelper.ResoveList(html, "<a href=\"#\" onclick=\"submitToCompose(", "/a>");
            foreach (string s in list) {
                string e = WebOpHelper.Resove(s, "');\">", " <");
                MailContract m = new MailContract();
                m.Email = HttpUtility.HtmlDecode(e.Replace("\r\n", "").Trim());
                mc.Add(m);
            }

            List<string> list2 = WebOpHelper.ResoveList(html, "<a href=\"ContactViewLight.aspx?ContactID", "/a>");
            int i = 0;
            foreach (string s in list2) {
                var s1 = WebOpHelper.Resove(s, "\">", "<");
                if (string.IsNullOrEmpty(s1)) {
                    mc[i].Name = mc[i].Email;
                }
                else {
                    mc[i].Name = HttpUtility.HtmlDecode(s1.Replace("\r\n", "").Trim());
                }
                i++;
            }
            return mc;
        }
        #endregion
    }
}
